package com.company.hrmadmin.modules.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.company.hrmadmin.common.constant.Result;
import com.company.hrmadmin.modules.entity.dto.salary.SalaryListDTO;
import com.company.hrmadmin.modules.entity.vo.AllowanceVO;
import com.company.hrmadmin.modules.entity.vo.ChargeVO;
import com.company.hrmadmin.modules.entity.vo.InsuranceVO;
import com.company.hrmadmin.modules.entity.vo.SalaryDetailVO;
import com.company.hrmadmin.modules.service.SalaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
 * 薪酬
 *
 * @author Song, Wei
 * Date: 2022/4/7 9:39
 */
@Slf4j
@RestController
@RequestMapping("/sal")
public class SalaryController {

    @Autowired
    private SalaryService salaryService;

    @RequestMapping(path = "/cal/salary", method = RequestMethod.GET)
    public Result<?> calAllSalary() {
        log.info("计算所有人员的薪水");
        return Result.success(salaryService.calAllSalary());
    }

    @RequestMapping(path = "/cal/cost", method = RequestMethod.GET)
    public Result<?> calAllCost() {
        log.info("计算所有的用人成本");
        return Result.success(salaryService.calAllCost());
    }

    @RequestMapping(path = "/list", method = RequestMethod.POST)
    public Result<IPage<SalaryDetailVO>> getSalaryPage(@RequestBody SalaryListDTO dto) {
        log.info("获取所有的薪酬页面列表，参数：{}", dto);
        return Result.success(salaryService.getSalaryPage(dto));
    }

    @RequestMapping(path = "/list/year", method = RequestMethod.GET)
    public Result<Set<Integer>> getSalaryYear(Integer userId) {
        log.info("获取薪酬页面存在的年份时间，参数：{}", userId);
        return Result.success(salaryService.getPSalaryYear(userId));
    }

    @RequestMapping(path = "/list/month", method = RequestMethod.GET)
    public Result<Set<Integer>> getSalaryMonth(Integer userId) {
        log.info("获取薪酬页面存在的月份时间，参数：{}", userId);
        return Result.success(salaryService.getPSalaryMonth(userId));
    }

    @RequestMapping(path = "/list/sort", method = RequestMethod.POST)
    public Result<Set<Integer>> getSalarySortList(Integer userId) {
        // TODO
        log.info("获取薪酬页面排序的结果，参数：{}", userId);
        return Result.success(salaryService.getPSalaryMonth(userId));
    }

    @RequestMapping(path = "/list/insurance", method = RequestMethod.GET)
    public Result<InsuranceVO> getPersonalInsurance(Integer salaryId) {
        log.info("获取个人所缴纳社会保险，参数：{}", salaryId);
        return Result.success(salaryService.getPInsuranceVOBySalaryId(salaryId));
    }

    @RequestMapping(path = "/list/allowance", method = RequestMethod.GET)
    public Result<AllowanceVO> getPersonalAllowance(Integer salaryId) {
        log.info("获取个人工资补贴，参数：{}", salaryId);
        return Result.success(salaryService.getPAllowanceVoBySalaryId(salaryId));
    }

    @RequestMapping(path = "/list/charge", method = RequestMethod.GET)
    public Result<ChargeVO> getPersonalCharge(Integer salaryId) {
        log.info("获取个人工资扣除款项，参数：{}", salaryId);
        return Result.success(salaryService.getPChargeVOBySalaryId(salaryId));
    }

    @RequestMapping(path = "/person/list", method = RequestMethod.POST)
    public Result<IPage<SalaryDetailVO>> getPersonalSalaryList(@RequestBody SalaryListDTO dto) {
        log.info("获取个人工资列表，参数：{}", dto);
        return Result.success(salaryService.getSalaryPageByUserId(dto));
    }

}
